<template>
	<view class="container">
		<view class="body">

			<!-- <uni-forms ref="form" :model="form" labelWidth="80px">
				<uni-forms-item label="教师工号/学号" name="teacherId">
					<uni-easyinput v-model="form.teacherId" placeholder="请输入" />
				</uni-forms-item>
				<uni-forms-item label="教师姓名" name="teacherName">
					<uni-easyinput v-model="form.teacherName" placeholder="请输入" />
				</uni-forms-item>
				<view> -->
			<uni-forms ref="form" :model="form" labelWidth="120px">
				<uni-forms-item label="设备名称" name="equipName">
					<uni-easyinput v-model="equipName" disabled="disabled" />
				</uni-forms-item>
				<uni-forms-item label="设备编号" name="equipId">
					<uni-easyinput v-model="equipId" disabled="disabled" />
				</uni-forms-item>
				<uni-forms-item label="协助人工号/学号" name="assistId">
					<uni-easyinput v-model="form.assistId" placeholder="请输入" @change="change" @input="input"
						@clear="clear" />
				</uni-forms-item>
				<uni-forms-item label="协助人姓名" name="assistName">
					<uni-easyinput v-model="form.assistName" placeholder="请输入" disabled="disabled" />
				</uni-forms-item>
				<view>
					<view v-for="(item, index) in table" :key="index">
						<view>
							<!-- <text>预约用户：{{item.teacherId}}</text><br>
								<text>开始时间：{{item.teacherName}}</text><br> -->
						</view>
					</view>
					<button class="mini" type="primary" @click="submit">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>

</template>

<script>
	// import {
	// 	addInstructor,
	// 	listInstructor,
	// 	searchT
	// } from "@/api/module/lyq/instructor.js"
	import {
		listAssist,
		addAssist,
		searchA,
		searchUser,
		checkUser,
		assistRole
	} from "@/api/module/wtc/assist.js"
	import {
		exit
	} from "process"
	export default {
		data() {
			return {
				exit: '',
				// 遮罩层
				loading: true,
				// 总条数
				total: 0,
				// 基本信息表格数据
				baseinfoList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				table: [],
				// queryParams: {
				// 	pageNum: 1,
				// 	pageSize: 10,
				// 	studentId: null,
				// 	name: null,
				// 	teacherName: null,
				// 	teacherId: null,
				// 	userId: null,
				// 	deptId: null,
				// 	createBy: null,
				// 	createTime: null,
				// 	updateBy: null,
				// 	updateTime: null,
				// 	remark: null,
				// 	note1: null,
				// 	note2: null,
				// 	note3: null,
				// 	note4: null,
				// 	note5: null,
				// 	note6: null,
				// 	note7: null,
				// 	note8: null,
				// 	note9: null,
				// 	note10: null
				// },
				// form: {
				// 	studentId: null,
				// 	name: null,
				// 	teacherName: null,
				// 	teacherId: null,
				// 	userId: null,
				// 	deptId: null,
				// 	createBy: null,
				// 	createTime: null,
				// 	updateBy: null,
				// 	updateTime: null,
				// 	remark: null,
				// 	note1: null,
				// 	note2: null,
				// 	note3: null,
				// 	note4: null,
				// 	note5: null,
				// 	note6: null,
				// 	note7: null,
				// 	note8: null,
				// 	note9: null,
				// 	note10: null
				// },
				queryParams: {
					receiverId: null,
					receiverName: null,
					assistName: null,
					assistId: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				form: {
					receiverId: null,
					receiverName: null,
					assistName: null,
					assistId: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				equipId: '',
				equipName: '',
			}
		},
		created() {
			// searchT().then(res => {
			// 	this.form = res
			// })
			const id = this.$route.query.id
			const name = this.$route.query.name
			this.equipId = id
			this.equipName = name
			searchA(this.equipId).then(res => {
				this.form = res
			})
			this.form.note1 = this.equipId
			assistRole(this.form).then(res => {
				this.exit = res
			})
		},
		onBackPress(options) {
			let self = this;
			if (options.from === 'navigateBack') {
				return false;
			}
			// console.log("要指定返回的页面");
			uni.reLaunch({
				url: '/pages/mine/index'
			})
			return true;
		},
		methods: {
			input(e) {
				// console.log("e:", e);
				if (e != '') {
					searchUser(e).then(res => {
						this.form.assistName = res
					})
				}
			},
			change(e) {
				// checkUser(this.form.assistName)
				if ((this.form.assistName == null || this.form.assistName == '') && e != '') {
					this.$modal.msgError("用户不存在")
				}
			},
			clear(e) {
				this.form.assistName = ''
				// console.log(this.form.assistName)
			},
			// change(e) {
			// 	console.log("e:", e);
			// },
			// input(e) {
			// 	console.log('输入内容：', e);
			// },
			// getList() {
			// 	this.loading = true;
			// 	listInstructor(this.queryParams).then(res => {
			// 		this.table = res.rows;
			// 		this.form.teacherId = res.rows.teacherId
			// 		this.form.teacherName = res.rows.teacherName
			// 		this.total = res.total;
			// 		this.loading = false;
			// 	});
			// },

			// submit(ref) {
			// 	this.$refs.form.validate().then(res => {
			// 		addInstructor(this.form).then(response => {
			// 			this.$modal.msgSuccess("提交成功")

			// 		})
			// 	})

			// }
			//返回
			returnBack() {
				this.$tab.reLaunch('/pages/mine/index');
			},
			submit(ref) {
				// setTimeout(1)
				// console.log(this.exit)
				if (this.exit == 0) {
					if (this.form.assistName == null || this.form.assistName == '') {
						this.$refs.form.validate().then(res => {
							this.$modal.msgError("无效信息")
						})
					} else {
						this.$refs.form.validate().then(res => {
							this.form.note1 = this.equipId
							addAssist(this.form).then(response => {
								this.$modal.msgSuccess("提交成功")
								// this.returnBack()
							})
						})
					}
				} else {
					if ((this.form.assistName == null || this.form.assistName == '') && this.form.assistId != '') {
						this.$modal.msgError("无效信息")
					}
					// else if ((this.form.assistName == null || this.form.assistName == '') && this.form.assistId == '') {
					// 	this.$refs.form.validate().then(res => {
					// 		addAssist(this.form).then(response => {
					// 			this.$modal.msgSuccess("提交成功")
					// 		})
					// 	})
					// }
					else {
						this.$refs.form.validate().then(res => {
							this.form.note1 = this.equipId
							addAssist(this.form).then(response => {
								this.$modal.msgSuccess("提交成功")
								// this.returnBack()
							})
						})
					}
				}
				// this.$refs.form.validate().then(res => {
				// 	addAssist(this.form).then(response => {
				// 		this.$modal.msgSuccess("提交成功")
				// 	})
				// })
				// this.returnBack()
			}
		},
	}
</script>

<style lang="scss">
	.title {
		/* display: block; */
		font-weight: bold;
		margin-top: 30px;
		margin-left: 5%;
		text-align: left;
	}

	.container {
		background-color: #fff;
	}

	.mini {
		width: 100%;
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.uni {
		width: 180px;
		float: left;
		position: relative;
		margin-top: 20px;
	}

	.body {
		padding: 15px;
		background-color: #fff;
	}

	.example {
		padding: 15px;
		background-color: #fff;
	}

	page {
		background-color: #ffffff;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}
</style>
